//Source file: D:\\test\\com\\ce\\pms\\custservice\\service\\impl\\EventManageServiceImpl.java

package com.ce.pms.custservice.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.util.Assert;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.service.ICodingGeneratorService;
import com.ce.pms.custservice.dao.ICustServiceEventDao;
import com.ce.pms.custservice.model.CustServiceEventDO;
import com.ce.pms.custservice.service.ICustEventStateMachineService;
import com.ce.pms.custservice.service.IEventManageService;
import com.ce.pms.custservice.vo.CustServiceEventSearchVO;
import com.ce.pms.custservice.vo.CustServiceEventVO;
import com.ce.pms.custservice.vo.SubmitTaskVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.system.custservice.model.CustEventKindDO;
import com.ce.pms.system.custservice.model.CustEventNatureDO;
import com.ce.pms.system.custservice.model.EmergencyDegreeDO;
import com.ce.pms.system.custservice.model.EventRegionDO;
import com.ce.pms.system.custservice.model.SeriousDegreeDO;
import com.ce.util.BeanUtil;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.support.Page;
import com.sitechasia.webx.core.utils.base.PopulateUtil;

public class EventManageServiceImpl extends PmsBaseServiceImpl implements
		IEventManageService {

	/**
	 * @return the houseService
	 */
	public IHouseService getHouseService() {
		return houseService;
	}

	/**
	 * @param houseService the houseService to set
	 */
	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}

	/***
	 * 功能描述:  产生事件编号<br>
	 * @return String
	 * @roseuid 4924D9A600AB
	 * Create author:高嵩 <br>
	 * Create on:2008-12-23  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */

	public String generateNo() {
		return this.getCodingGeneratorService().generateCustServEventCodeing();

	}

	/***
	 * 功能描述:  装配当前事件和关联事件<br>
	 * @param materEvent
	 * @param associatedEvent
	 * Create author:高嵩 <br>
	 * Create on:2008-12-23  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */

	public void assemble2D(CustServiceEventDO materEvent,
			CustServiceEventDO associatedEvent) {
		Assert.notNull(materEvent);Assert.notNull(associatedEvent);
		materEvent.addAssociateEvent(associatedEvent);
	}

	/**
	 * 功能描述:检查指定的事件是否能创建派工单  <br>
	 * @param custEventId
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2009-1-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void checkIsAllowAddDispatchForm(Long custEventId){
		CustServiceEventDO custEventDo = this.custServiceEventDao.findById(custEventId);
		Boolean res = custEventDo.isAllowAddDispatchForm();
		if (!res) {
			throw new BusinessException("custservice:custservice_cannot_adddform_exception",
								BusinessException.WARNING);
		}
	}

		/***
	    * 功能描述:  新建客服事件<br>
	    * @param custServiceEventVO
	    * @return
	    * @roseuid 4924D5ED02AF
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public CustServiceEventVO addCustEvent(CustServiceEventVO custServiceEventVO) {
		CustServiceEventDO custServiceEventDO = new CustServiceEventDO();
		custServiceEventDO = assembleV2D(custServiceEventVO, custServiceEventDO);
		custServiceEventDO.setRecorderTime(this.getCustServiceEventDao().getDate());
		//根据新建的事件有效状态,设置客服事件各个状态的跃迁
		this.getCustEventStateMachineService().decideAllStatuzWithAddCSEvent(custServiceEventDO);
		//设置(生成)事件编号
		//Assert.notNull(generateNo());
		custServiceEventDO.setEventNo(generateNo());
		this.getCustServiceEventDao().saveObject(custServiceEventDO);
		return assembleD2V(custServiceEventDO,custServiceEventVO);
	}

		/***
	    * 功能描述:  修改客服事件<br>
	    * @param custServiceEventVO
	    * @return CustServiceEventVO
	    * @roseuid 4924F5170203
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public CustServiceEventVO editCustEvent(CustServiceEventVO custServiceEventVO) {
		 CustServiceEventDO custServiceEventDO = null;
		 custServiceEventDO = this.isExistsCustServiceByID(custServiceEventVO.getKeyword());
		 //判断事件是否允许修改
		if(custServiceEventDO.isAllowUpdate()){
			//根据修改后的事件有效状态,设置客服事件各个状态的跃迁
			this.getCustEventStateMachineService().decideALLStatuzWithEditCSEvent(custServiceEventVO, custServiceEventDO);
			assembleV2D(custServiceEventVO, custServiceEventDO);
			this.getCustServiceEventDao().updateObject(custServiceEventDO);
			return assembleD2V(custServiceEventDO, custServiceEventVO);
		}else{

			throw new BusinessException("custservice:notallow_cannotupdate_custEvent");
		}
	}

	   /***
	    * 功能描述: 归档 <br>
	    * @param custServiceEventVO
	    * @roseuid 49251D61033C
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void archivism(CustServiceEventVO custServiceEventVO) {
		CustServiceEventDO custServiceEventDO = null;
		custServiceEventDO = this.isExistsCustServiceByID(custServiceEventVO.getKeyword());
			//设置事件状态"已归档
		custServiceEventDO.setEStatuzHasArchivismed();
		custServiceEventDO.getSysInfo().setModifyDate(this.getCustServiceEventDao().getDate());
		this.getCustServiceEventDao().updateObject(custServiceEventDO);


	}


	   /***
	    * 功能描述:  作废客服事件<br>
	    * @param custServiceEventVO
	    * @roseuid 4924F16C005D
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void setAsideCustEvent(CustServiceEventVO custServiceEventVO) {
		Assert.notNull(custServiceEventVO,"customerEvent notNull");
		CustServiceEventDO custServiceEventDO = null;
		custServiceEventDO = this.isExistsCustServiceByID(custServiceEventVO.getKeyword());

		 //是否允许事件作废
		if(custServiceEventDO.isAllowCustomerServiceEventSetAside())
		 {
			 //设置备注
			custServiceEventDO.setRemark(custServiceEventVO.getRemark());
				//设置事件状态"作废
			custServiceEventDO.setEStatuzLogicDele();
			this.getCustServiceEventDao().updateObject(custServiceEventDO);
		 }else{
				throw new BusinessException("custservice:custEvent_cannot_setAside");
		 	}
	}

	/***
	 * 功能描述:  <br>
	 * @param custEventID
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2008-12-25  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private CustServiceEventDO isExistsCustServiceByID(Long custEventID){
		Assert.notNull(custEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO = this.custServiceEventDao.findById(custEventID);

		if(BlankUtil.isBlank(custServiceEventDO)){
			throw new BusinessException("custservice:custServiceNotExistsException",BusinessException.WARNING);
		}
		return custServiceEventDO;
	}

	   /***
	    * 功能描述:  通知事件已提交<br>
	    * @param csEventID
	    * @roseuid 4933C04801E4
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void noteSubmitTask(Long csEventID) {
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		//设置事件状态为"已提交"
		custServiceEventDO.setEStatuzSubmit();
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}


	   /***
	    * 功能描述:  通知新增回访登记<br>
	    * @param csEventID
	    * @roseuid 4928125C0222
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void noteAddReturnVisit(Long csEventID) {
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		//客服助理登记回访，根据业务规则，设置事件状态跃迁状态
		this.getCustEventStateMachineService().decideAllStatuzWithAddReturnVisit(custServiceEventDO);
		this.getCustServiceEventDao().updateObject(custServiceEventDO);

	}


	   /***
	    * 功能描述:  通知阅签<br>
	    * @param csEventID
	    * @roseuid 492824AE037A
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void noteAddSignReading(Long csEventID) {
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		//领导阅签，根据业务规则，设置事件状态跃迁状态
		this.getCustEventStateMachineService().decideAllStatuzWithAddSignReading(custServiceEventDO);
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}


	   /***
	    * 功能描述:  通知新增抽检<br>
	    * @param csEventID
	    * @roseuid 492A58910109
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void noteAddCheckRecord(Long csEventID) {
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		//设置是否抽检"已抽检" checkStatuz=1
		custServiceEventDO.setCStatuzHasChecked();
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}


	/***
	 * 功能描述:  判断事件是否可以修改<br>
	 * @param csEventID 当前事件ID
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2009-1-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowEditCustEvent(Long csEventID){
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		if(custServiceEventDO.isAllowUpdate()){
			return true;
		}else{
			throw new BusinessException("custservice:notallow_cannotupdate_custEvent");
		}
	}

	/***
	 * 功能描述:  判断事件是否允许作废<br>
	 * @param csEventID
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2009-1-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean  isAllowSetAsideEvent(Long csEventID){
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		if(custServiceEventDO.isAllowCustomerServiceEventSetAside())
		 {
			return true;
		 }else{
			throw new BusinessException("custservice:custEvent_cannot_setAside");
		 }
	}



	   /***
	    * 功能描述: 判断是否可以进行抽检 <br>
	    * @param csEventID
	    * @return
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	 public boolean isAllowCheck(Long csEventID){
		 Assert.notNull(csEventID,"customerEvent ID notNull");
		 CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		 if(!custServiceEventDO.isAllowCheck()){
			 throw new BusinessException("custservice:customerEvent_Cannot_AllowCheckException",BusinessException.WARNING);
		 }
		 return true;
	 }


	 /***
	    * 功能描述: 判断是否可以进行回访 <br>
	    * @param csEventID
	    * @return
	    * Create author:高嵩 <br>
	    * Create on:2008-12-26  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public boolean isAllowReturnVisit(Long csEventID){
			 Assert.notNull(csEventID,"customerEvent ID notNull");
			 CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
			 if(!custServiceEventDO.isAllowReturnVisit()){
				 throw new BusinessException("custservice:customerEvent_Cannot_ReturnVisitException",BusinessException.ERROR);
			 }
			 return true;

	   }


		/***
		 * 功能描述:  判断是否允许作废回访
		 * 当事件状态为EventStatuz=003或EventStatuz=004时返回ture,否则返回false<br>
		 * @return
		 * Create author:高嵩 <br>
		 * Create on:2009-1-4  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		public boolean isAllowSetAsideReturnVisit(Long csEventID){
			 Assert.notNull(csEventID,"customerEvent ID notNull");
			 CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);

			 if(!custServiceEventDO.isAllowSetAsideReturnVisit()){
				 throw new BusinessException("custservice:customerEvent_Cannot_SetAsideReturnVisitException",BusinessException.ERROR);
			 }
			return true;
		}

		/***
		 * 功能描述: 判断是否允许进行阅签 <br>
		 * @param csEventID
		 * @return
		 * Create author:高嵩 <br>
		 * Create on:2009-1-4  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		public boolean isAllowReadView(Long csEventID){
			 Assert.notNull(csEventID,"customerEvent ID notNull");
			 CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
			 if(!custServiceEventDO.isAllowReadView()){
				 throw new BusinessException("custservice:customerEvent_Cannot_ReadViewException",BusinessException.ERROR);
			 }
			return true;
		}


		/***
		 * 功能描述:  判断是否可以进行归档操作<br>
		 * @param csEventID
		 * @return
		 * Create author:高嵩 <br>
		 * Create on:2009-1-7  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		public boolean isAllowArchivism(Long csEventID){
			Assert.notNull(csEventID,"customerEvent ID notNull");
			CustServiceEventDO custServiceEventDO = null;
			custServiceEventDO = this.isExistsCustServiceByID(csEventID);
			//判断是否允许归档
			if(!custServiceEventDO.isAllowArchivism())
				throw new BusinessException("custservice:custEvent_cannot_archivism");
			return true;

		}

	   /***
	    * 功能描述:  通知作废抽检<br>
	    * @param csEventID
	    * @roseuid 492A58910109
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void noteSetAsideCheckRecord(Long csEventID){
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
		custServiceEventDO.resetCStatuz();
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}

	   /***
	    * 功能描述: 因为发生作废回访登记,重置事件状态 <br>
	    * @param csEventID
	    * @roseuid 4928209802AF
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
//	public void resetRV1RStatuzBySetAsideRVisit(Long csEventID) {
//		Assert.notNull(csEventID,"customerEvent ID notNull");
//		CustServiceEventDO custServiceEventDO =this.isExistsCustServiceByID(csEventID);
//		//当发生作废事件关联的回访登记时,设置事件的状态跃迁
//		//this.getCustEventStateMachineService().resetRVisit1RStatuzBySetAsideRVisit(custServiceEventDO);
//		this.getCustServiceEventDao().updateObject(custServiceEventDO);
//	}


	   /***
	    * 功能描述: 关联事件 <br>
	    * @param theEventID
	    * @param associatedCSEventIDs
	    * @roseuid 49251EBF02DE
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void associateCSEvent(Long theEventID,
			List<Long> associatedCSEventIDs) {
		CustServiceEventDO custServiceEventDO = null;
		Assert.notNull(theEventID);Assert.notEmpty(associatedCSEventIDs);
		custServiceEventDO = this.isExistsCustServiceByID(theEventID);

		for(Long associatedCSEventID : associatedCSEventIDs){
			//add master 增加关系数目
			custServiceEventDO.increaseRelationship();
			//add slave
			CustServiceEventDO associatedEventDO = this.isExistsCustServiceByID(associatedCSEventID);
			//增加被关联关系数目
			associatedEventDO.increaseRelationship();
			//关联事件
			assemble2D(custServiceEventDO, associatedEventDO);


		}
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}


	   /***
	    * 功能描述:  解除事件<br>
	    * @param MastEventID
	    * @param associatedEventID
	    * @roseuid 49388F75031C
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void riddanceCSEvent(Long MastEventID,Long associatedEventID) {

		Assert.notNull(MastEventID,"mastEventID notNull");
		Assert.notNull(associatedEventID,"associatedEventID notNull");
		CustServiceEventDO custServiceEventDO = this.isExistsCustServiceByID(MastEventID);
		//删除关系数目
		custServiceEventDO.decreaseRelationship();
		CustServiceEventDO associatedEventDO = this.getCustServiceEventDao().findById(associatedEventID);
		//删除关系数目
		associatedEventDO.decreaseRelationship();
		//解除事件
		custServiceEventDO.removeAssociateEvent(associatedEventDO);
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}


	   /***
	    * 功能描述: 手动触发事件完成 <br>
	    * @param csEventID
	    * @roseuid 4942336401B5
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public void manualTriggerComplete(Long eventID) {
		Assert.notNull(eventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO = isExistsCustServiceByID(eventID);
		if(isAllowManualTriggerComplete(custServiceEventDO)){
			//客服手动触发事件状态已完成,根据业务规则判断所有状态跃迁
			this.getCustEventStateMachineService().decideAllStatuzWithComplete(custServiceEventDO);
			custServiceEventDO.getSysInfo().setModifyDate(this.getCustServiceEventDao().getDate());
			this.getCustServiceEventDao().updateObject(custServiceEventDO);
		}
	}

	/***
	 * 功能描述: 是否充许事件完工 <br>
	 * @param eventDO
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Boolean isAllowManualTriggerComplete(CustServiceEventDO eventDO){
		return this.getCustEventStateMachineService().isAllowManualTriggerComplete(eventDO);
	}


	   /***
	    * 功能描述:  通过事件ID查询事件<br>
	    * @param csEventID
	    * @return
	    * @roseuid 4941C1DE01B5
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public CustServiceEventVO getCustServEventByID(Long csEventID){
		Assert.notNull(csEventID,"customerEvent ID notNull");
		CustServiceEventDO custServiceEventDO = this.isExistsCustServiceByID(csEventID);
		CustServiceEventVO custServiceEventVO = new CustServiceEventVO();
		custServiceEventVO = this.assembleD2V(custServiceEventDO, custServiceEventVO);
		return custServiceEventVO;

	}


	   /***
	    * 功能描述: 查询客服事件列表 <br>
	    * @param custServiceEventSearchVO
	    * @return List<CustServiceEventVO>
	    * @roseuid 494329B00399
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public List<CustServiceEventVO> queryCustServEventList(CustServiceEventSearchVO custServiceEventSearchVO) {
		List<CustServiceEventDO> custServiceEventDOList = this.getCustServiceEventDao().queryCustServEventList(custServiceEventSearchVO);
		return CustServiceEventDOToVO(custServiceEventDOList);
	}


	   /***
	    * 功能描述:  按页查询客服事件<br>
	    * @param custServiceEventSearchVO
	    * @return Page
	    * @roseuid 4943444B01E4
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public Page queryCustServEventByPage(CustServiceEventSearchVO custServiceEventSearchVO) {
		Page page = this.getCustServiceEventDao().queryCustServEventByPage(custServiceEventSearchVO);
		List<CustServiceEventDO> custServiceEventDOList = page.getResult();
		page.setResult(CustServiceEventDOToVO(custServiceEventDOList));
		return page;
	}


	   /***
	    * 功能描述:  查询关联事件<br>
	    * @param custServiceEventSearchVO
	    * @return List<CustServiceEventVO>
	    * @roseuid 494345BF0128
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public List<CustServiceEventVO> queryAssociatedCSEventList(CustServiceEventSearchVO custServiceEventSearchVO) {
		List<CustServiceEventVO> custServiceEventVOList = this.getCustServiceEventDao().queryAssociatedCSEventList(custServiceEventSearchVO);
		return custServiceEventVOList;
	}


	   /***
	    * 功能描述:  分页查询关联事件<br>
	    * @param custServiceEventSearchVO
	    * @return Page
	    * @roseuid 4943693E032C
	    * Create author:高嵩 <br>
	    * Create on:2008-12-23  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	public Page queryAssociatedCSEventByPage(CustServiceEventSearchVO custServiceEventSearchVO) {
		Page page = this.getCustServiceEventDao().queryAssociatedCSEventByPage(custServiceEventSearchVO);
		return page;

	}


	 /***
	    * 功能描述:  通知撤消提交任务<br>
	    * @param id  事件ID
	    * Create author:高嵩 <br>
	    * Create on:2008-12-29  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */

	public void cancelSubmitTask(Long taskID, Long csEventID) {
		// TODO Auto-generated method stub
		CustServiceEventDO custServiceEventDO = this.isExistsCustServiceByID(csEventID);
		this.getCustEventStateMachineService().resetEStatuzByRevokeSubmitTask(taskID, custServiceEventDO);
		this.getCustServiceEventDao().updateObject(custServiceEventDO);
	}

	/**
	 * @author 高嵩
	 * @param custServEventDO
	 * @param custServEventVO
	 * @return CustServiceEventVO
	 * @roseuid 4924F2D300AB
	 */
	public CustServiceEventVO assembleD2V(CustServiceEventDO custServEventDO,
			CustServiceEventVO custServEventVO) {

		Assert.isTrue(PopulateUtil.populate(custServEventDO, custServEventVO));
		//房号
		if(!BlankUtil.isBlank(custServEventDO.getHouse())){
			custServEventVO.setHouseKeyword(custServEventDO.getHouse().getKeyword());
			custServEventVO.setHouseNumber(custServEventDO.getHouseNumber());
		}
		if(!BlankUtil.isBlank(custServEventDO.getCustomerServiceEventNatureDO())){
//			事件性质
			custServEventVO.setEventNatureKeyword(custServEventDO.getCustomerServiceEventNatureDO().getKeyword());
			custServEventVO.setCustServEventNatureName(custServEventDO.getCustomerServiceEventNatureDO().getName());
		}
		if(!BlankUtil.isBlank(custServEventDO.getCustomerServiceEventKindDO())){
//			事件类型
			custServEventVO.setCustServEventKindKeyword(custServEventDO.getCustomerServiceEventKindDO().getKeyword());
			custServEventVO.setCustServEventKindName(custServEventDO.getCustomerServiceEventKindDO().getName());
		}
		if(!BlankUtil.isBlank(custServEventDO.getEventRegionDO())){
//			事件区域名称
			custServEventVO.setEventRegionKeyword(custServEventDO.getEventRegionDO().getKeyword());
			custServEventVO.setEventRegionName(custServEventDO.getEventRegionDO().getName());
		}
		if(!BlankUtil.isBlank(custServEventDO.getEmergencyDegreeDO())){
//			紧急程度EmergencyDegreeDO
			custServEventVO.setEmergencyDegreeKeyword(custServEventDO.getEmergencyDegreeDO().getKeyword());
			custServEventVO.setEmergencyDegreeName(custServEventDO.getEmergencyDegreeDO().getName());
		}
		if(!BlankUtil.isBlank(custServEventDO.getSeriousDegreeDO())){
//			严重程度
			custServEventVO.setSeriousDegreeKeyword(custServEventDO.getSeriousDegreeDO().getKeyword());
			custServEventVO.setSeriousDegreeName(custServEventDO.getSeriousDegreeDO().getName());
		}
		if(!BlankUtil.isBlank(custServEventDO.getRelationship())){
			//关联数目
			custServEventVO.setRelationship(custServEventDO.getRelationship());
		}
		if(null!=custServEventDO.getAppointment() && !"".equals(custServEventDO.getAppointment())){
			custServEventVO.setAppointment(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(custServEventDO.getAppointment()));
		}
		//custServEventVO.setRecorderTime(this.getCustServiceEventDao().getDate().toString());
		//修改时间
		if(null!=custServEventDO.getSysInfo().getModifyDate()){
			custServEventVO.setModifyDate(custServEventDO.getSysInfo().getModifyDate());
		}
		custServEventVO.setEventStatuzStr(custServEventVO.getEventStatuz());
		custServEventVO.setReturnVisitStatuzStr(custServEventVO.getReturnVisitStatuz());
		custServEventVO.setValidityStr(custServEventVO.getValidity());
		custServEventVO.setReviewerStatuzStr(custServEventVO.getReviewerStatuz());
		return custServEventVO;
	}


	/**
	 * 转换VO 到 DO
	 * @author 高嵩
	 * @param custServEventVO -
	 *            客户事件VO
	 * @param custServEventDO -
	 *            客户事件DO
	 * @return CustServiceEventDO
	 * @roseuid 4924F34F002E
	 */
	public CustServiceEventDO assembleV2D(CustServiceEventVO custServEventVO,
			CustServiceEventDO custServEventDO) {

		BeanUtil.convertVoAsDo(custServEventVO, custServEventDO);
		Assert.notNull(custServEventVO.getEventContent());
		Assert.notNull(custServEventVO.getContact());
		Assert.notNull(custServEventVO.getValidity());
		custServEventDO.setContact(custServEventVO.getContact());
		custServEventDO.setEventContent(custServEventVO.getEventContent());
		custServEventDO.setValidity(custServEventVO.getValidity());
		custServEventDO.setRelationship(new Short("0"));

		if(null!=custServEventVO.getCreator() && !"".equals(custServEventVO.getCreator())){
			custServEventDO.setSysInfo(new SysInfo(custServEventVO.getCreator(),this.getCustServiceEventDao().getDate()));
		}
		if(null!=custServEventVO.getModifier() && !"".equals(custServEventVO.getModifier())){
			custServEventDO.getSysInfo().setModifier(custServEventVO.getModifier());
			custServEventDO.getSysInfo().setModifyDate(this.getCustServiceEventDao().getDate());
		}
		if(null!=custServEventVO.getHouseKeyword() && !"".equals(custServEventVO.getHouseKeyword())){
			//房屋
			custServEventDO.setHouse(new HouseDomain(custServEventVO.getHouseKeyword()));
			//如果手动输入的房号不等于空时
		}else if(null!=custServEventVO.getHouseNumber() && !"".equals(custServEventVO.getHouseNumber())){
			HouseDomain houseDomain = this.getHouseService().getHouseByNumber(custServEventVO.getHouseNumber());
			if(null!=houseDomain && null!=houseDomain.getKeyword()){
				custServEventDO.setHouse(new HouseDomain(houseDomain.getKeyword()));
			}else{
				throw new BusinessException("house:pro_right_number_not_exist_exception",BusinessException.WARNING);
			}
		}
		if(null!=custServEventVO.getEventRegionKeyword() && !"".equals(custServEventVO.getEventRegionKeyword())){
			 //事件区域
			custServEventDO.setEventRegionDO(new EventRegionDO(custServEventVO.getEventRegionKeyword()));
		}
		Assert.notNull(custServEventVO.getCustServEventKindKeyword());
		//事件类型
		custServEventDO.setCustomerServiceEventKindDO(new CustEventKindDO(custServEventVO.getCustServEventKindKeyword()));
		Assert.notNull(custServEventVO.getEventNatureKeyword());
		//客户事件性质
		custServEventDO.setCustomerServiceEventNatureDO(new CustEventNatureDO(custServEventVO.getEventNatureKeyword()));

		if(null!=custServEventVO.getSeriousDegreeKeyword() && !"".equals(custServEventVO.getSeriousDegreeKeyword())){
			//严重程度
			custServEventDO.setSeriousDegreeDO(new SeriousDegreeDO(custServEventVO.getSeriousDegreeKeyword()));
		}
		if(null!=custServEventVO.getEmergencyDegreeKeyword() && !"".equals(custServEventVO.getEmergencyDegreeKeyword())){
			//紧急程度
			custServEventDO.setEmergencyDegreeDO(new EmergencyDegreeDO(custServEventVO.getEmergencyDegreeKeyword()));
		}


		if(null!=custServEventVO.getAppointment() && !"".equals(custServEventVO.getAppointment())){
			try {
				custServEventDO.setAppointment( new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(custServEventVO.getAppointment()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}




		return custServEventDO;
	}


	/**
	 * 功能描述:批量将Domain转换为VO<br>
	 * @param domainlist
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2008-10-7  <br>
	 */
	private List<CustServiceEventVO> CustServiceEventDOToVO(List<CustServiceEventDO> domainlist){
		if(domainlist == null || domainlist.size() == 0) return null;
		List<CustServiceEventVO> voList = new ArrayList<CustServiceEventVO>();
		for(Iterator<CustServiceEventDO> iterator = domainlist.iterator(); iterator.hasNext();){
			CustServiceEventDO cdo = iterator.next();
			CustServiceEventVO cvo = assembleD2V(cdo, new CustServiceEventVO());
			voList.add(cvo);
		}
		return voList;
	}

	private ICustServiceEventDao custServiceEventDao;

	private ICustEventStateMachineService custEventStateMachineService;

	private ICodingGeneratorService codingGeneratorService;


	private IHouseService houseService;
//	private ISubmitTaskService submitTaskService;
//
//	public void setSubmitTaskService(ISubmitTaskService submitTaskService)
//	{
//		this.submitTaskService = submitTaskService;
//	}
	/**
	 * @return the codingGeneratorService
	 */
	public ICodingGeneratorService getCodingGeneratorService() {
		return codingGeneratorService;
	}

	/**
	 * @param codingGeneratorService the codingGeneratorService to set
	 */
	public void setCodingGeneratorService(
			ICodingGeneratorService codingGeneratorService) {
		this.codingGeneratorService = codingGeneratorService;
	}

	/**
	 * @return the custEventStateMachineService
	 */
	public ICustEventStateMachineService getCustEventStateMachineService() {
		return custEventStateMachineService;
	}

	/**
	 * @param custEventStateMachineService the custEventStateMachineService to set
	 */
	public void setCustEventStateMachineService(
			ICustEventStateMachineService custEventStateMachineService) {
		this.custEventStateMachineService = custEventStateMachineService;
	}

	/**
	 * @return the custServiceEventDao
	 */
	public ICustServiceEventDao getCustServiceEventDao() {
		return custServiceEventDao;
	}

	/**
	 * @param custServiceEventDao
	 *            the custServiceEventDao to set
	 */
	public void setCustServiceEventDao(ICustServiceEventDao custServiceEventDao) {
		this.custServiceEventDao = custServiceEventDao;
	}

	/**
	 * @roseuid 49436CB00148
	 */
	public EventManageServiceImpl() {

	}

	public Map<Long,String> createEventTask(SubmitTaskVO submitTaskVO)
	{

		Assert.notNull(submitTaskVO);
		Long eventID = submitTaskVO.getCustServiceEventId();
		CustServiceEventDO eventDO = isExistsCustServiceByID(eventID);
		StringBuilder cannotSumbitStatus = new StringBuilder();
		// "完工/待归档/归档/作废"状态的事件不可以提交
		cannotSumbitStatus.append(CustServiceEventDO.EVENT_STATUS_COMPLETE_CODE).append(";");
		cannotSumbitStatus.append(CustServiceEventDO.EVENT_STATUS_ARCHIVING_CODE).append(";");
		cannotSumbitStatus.append(CustServiceEventDO.EVENT_STATUS_ARCHIVED_CODE).append(";");
		cannotSumbitStatus.append(CustServiceEventDO.EVENT_STATUS_CANCEL_CODE).append(";");
		//如果状态不在禁止提交之列，那么就创建任务
		if(cannotSumbitStatus.indexOf(eventDO.getEventStatuz())>-1)
		{
			throw new BusinessException("custservice:statusNotAllowSubmitEventException",BusinessException.WARNING);
		}
		//校验不通过的 部门<id,name> , 如果校验全通过，返回null
//		Map<Long,String> departmentsNotAllow = submitTaskService.checkDepartmentsEventSubmitingNotAllow(submitTaskVO);
//		if(departmentsNotAllow!=null && !departmentsNotAllow.isEmpty())
//		{
//			return departmentsNotAllow;
//		}
//		//如果状态不在禁止提交之列，那么就创建任务，剩下的判断由SubmitTaskService完成
//		submitTaskService.addTask(eventID, submitTaskVO);
		return null;
	}


}
